<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/include/tagLib.jsp" %>
<!doctype html>
<html lang="en">
<head>
    <title>${sieName}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <%@include file="/include/cssLib.jsp" %>
</head>

<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-md-12">
            <!-- 菜单 -->
            <tag:nav key="sysAdmin"/>

            <div class="tab-content">
                <div class="tab-pane active">
                    <div class="card col-md-10 col-md-offset-1">
                        <tag:sys-nav key="apiAppList"/>
                        <div class="card-header">
                            <div class="row">
                                <form id="searchForm" action="${ctx}/adminConsole/superAdmin/apiAppList" method="post">
                                    <div class="col-md-2">
                                        <input type="text" name="QF__EQ__appName" value="${searchCondMap['QF__EQ__appName']}" class="form-control clearable" placeholder="应用名"/>
                                    </div>
                                    <div class="col-md-1">
                                        <button type="submit" class="btn btn-twitter"><i class="fa fa-search"></i></button>
                                        <input type="hidden" id="pageNo" name="pageNo"/>
                                        <input type="hidden" id="pageSize" name="pageSize" />
                                        <input type="hidden" id="orderBy" name="page.orderBy" value="${orderBean.orderBy}"/>
                                        <input type="hidden" id="order" name="page.order" value="${orderBean.order}"/>
                                    </div>
                                </form>
                            </div>
                        </div>
                        <div class="card-content">
                            <tag:paging-simple page="${pageResult}"/>
                            <div class="table-responsive">
                                <table id="datatable" class="table table-bordered">
                                    <thead>
                                    <tr>
                                        <th class="text-center">应用名</th>
                                        <th>appKey</th>
                                        <th>白名单IP</th>
                                        <th>授权api</th>
                                        <th width="100">更新者</th>
                                        <th width="130" sort-field="update_time">操作时间</th>
                                        <th width="60">状态</th>
                                        <th>备注</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:forEach items="${pageResult.result }" var="data">
                                        <tr>
                                            <td class="text-center">${data.appName}</td>
                                            <td id="${fns:encryptId(data.id)}"><a href="javascript:viewAppKey('${fns:encryptId(data.id)}');">查看</a></td>
                                            <td>${data.whiteIp}</td>
                                            <td>
                                                <c:forEach items="${fn:split(data.authApi, '|')}" var="api">
                                                    <code>${api }</code>&nbsp;&nbsp;
                                                </c:forEach>
                                            </td>
                                            <td>${data.updateBy}</td>
                                            <td>${fns:formatTimeAgo(data.updateTime)}</td>
                                            <td>
                                                <c:if test="${data.status eq 0}"><label class='label label-danger'>禁用</label></c:if>
                                                <c:if test="${data.status eq 1}"><label class='label label-success'>正常</label></c:if>
                                            </td>
                                            <td>${data.remarks}</td>
                                            <td>
                                                <a  href="javascript:;" onclick="clearCache('${fns:encryptId(data.appKey)}')">清理缓存</a>
                                            </td>
                                        </tr>
                                    </c:forEach>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <tag:paging page="${pageResult}"/>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%@include file="/include/sidebarRight.jsp" %>
</body>
<%@include file="/include/scriptLib.jsp" %>
<script type="text/javascript">
    $(document).ready(function() {
        //绑定排序
        FormUtil.bindOrder();

        //日期时间范围
        laydate.render({
            elem: '#rangeCreateDate'
            ,type: 'datetime'
            ,max: 0
            ,range: true
        });
    });

    function viewAppKey(id){
        HttpUtil.ajaxAsyncJsonPost('/adminConsole/superAdmin/getApiAppKey', {id: id}, function(appKey){
            $("#datatable tbody").find("#"+id+"").html("<code>"+appKey+"</code>");
        });
    }

    function clearCache(key){
        HttpUtil.ajaxAsyncJsonPost('/adminConsole/superAdmin/clearApiAppCache', {key: key}, function(message){
//            dialogRightTopTip(message, 2000);
            dialogCenterTopTip(message);
        });
    }
</script>

</html>